/*
package com.ruoyi.job.task;

import com.ruoyi.common.core.constant.ScheduleConstants;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.job.domain.EtlScriptTask;
import com.ruoyi.job.domain.EtlTaskInst;
import com.ruoyi.job.domain.EtlTaskState;
import com.ruoyi.job.domain.SysJob;
import com.ruoyi.job.mapper.EtlScriptTaskMapper;
import com.ruoyi.job.mapper.EtlTaskInstMapper;
import com.ruoyi.job.mapper.EtlTaskStateMapper;
import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

*/
/**
 * 执行kettle脚本任务
 *//*

@Component("etlKettleExecuteTask")
public class EtlKettleExecuteTask {
    private Logger logger = LoggerFactory.getLogger(EtlKettleExecuteTask.class);

    @Autowired
    private RedisService redisService;

    @Autowired
    private Scheduler scheduler;

    @Autowired
    private EtlTaskInstMapper etlTaskInstMapper;

    @Autowired
    private EtlScriptTaskMapper etlScriptTaskMapper;

    @Autowired
    private EtlTaskStateMapper etlTaskStateMapper;

    private static String firstRun = "true";

    ExecutorService pool = Executors.newFixedThreadPool(20);

    public void initWithParams(String taskName) {
        */
/**
         * 如果选择“执行一次”，则前端必须传递执行日期
         *//*

        String exeDate = "";
        SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMdd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        exeDate=sdf.format(calendar.getTime());

        logger.info("执行任务开始："+Thread.currentThread().getName()+",sjrq="+exeDate);

        */
/*******查询前置任务昨日是否执行成功*************//*

        //查询待处理的任务//不包含执行中的 //String minDate=taskDao.queryMinDateScriptTask(con);//包含执行中的
        List<EtlScriptTask> listTask = etlScriptTaskMapper.queryETLScriptTask();
        logger.info("本次共查询到待处理任务 "+listTask.size()+" 条");

        for(int i=0; i<listTask.size(); i++) {
            //当前要执行的任务
            EtlScriptTask taskBean = listTask.get(i);
            //查询任务之前的定时任务是否执行,第一次运行不需要检查
            int countUndeal = 0;
            //主要解决批量执行任务的时候，保证通一个任务一次按照日期运行
            if(!Boolean.parseBoolean(firstRun)){
                countUndeal = etlScriptTaskMapper.queryUndeal(taskBean.getTaskId(),taskBean.getTaskDate());
            }else{
                countUndeal=0;
            }
            if(countUndeal<=0){//测试 暂时注释
                if(taskBean.getScriptType() >= 3){
//                    executeJar(pool,con,taskBean);
                }else{
                    executeScript(pool,taskBean,etlScriptTaskMapper);
                }
            }else{
                etlScriptTaskMapper.finishETLScriptTask(taskBean.getStatus(), "前日任务未执行！", taskBean.getScripttaskId());
                etlScriptTaskMapper.updateTaskInstAndState(taskBean.getTaskId(),taskBean.getTaskDate(),
                                            new Date(),taskBean.getStatus(),0,"前日任务未执行！");
            }
        }




    }

    public static void executeScript(ExecutorService pool,EtlScriptTask taskBean,EtlScriptTaskMapper etlScriptTaskMapper) throws Exception{
        //更新状态为处理中
        etlScriptTaskMapper.finishETLScriptTask(ETLScriptTaskDao.STATUS_DEALING, "脚本执行中", taskBean.getScripttaskId());
        etlScriptTaskMapper.updateTaskInstAndState(taskBean,new Date(),ETLScriptTaskDao.STATUS_DEALING,0,"脚本执行中...");
        //执行任务
        DealTask dt = new DealTask(taskBean,new Date());
        pool.execute(dt);
    }
}
*/
